public class Demo22 {
    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread thread1 = new Thread(() -> {
           synchronized(locker1){
               System.out.println("thread1 拿到locker1");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               synchronized(locker2){
                   System.out.println("thread1 获取了两把锁");
               }
           }
        });

        Thread thread2 = new Thread(() -> {
           synchronized (locker1){
               System.out.println("thread2 拿到locker");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               synchronized(locker1){
                   System.out.println("thread2 获取了两把锁");
               }
           }
        });

        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
    }
}
